/**
 * https://leetcode.cn/problems/minimum-window-substring/description/
 * 76. 最小覆盖子串
 * difficulty, 赖德檀 2024.09.04
 * 滑动窗口
 */



class Solution {
public:
    string minWindow(string s, string t) {
        unordered_map<char,int>mp;
        int num=0;
        int len=INT_MAX;
        int k=0;
        for(int i=0;i<t.size();i++)
        {
            mp[t[i]]++;
        }
        int sum=t.size();
        for(int l=0,r=0;r<s.size();r++)
        {
            if(mp[s[r]]-->0)
            sum--;
            if(sum==0)
            {
                while(mp[s[l]]<0)
                {
                    mp[s[l++]]++;
                }
                if(len>r-l+1)
                {
                    k=l;
                    len=r-l+1;
                }  
            }
        }
        return len==INT_MAX?"":s.substr(k,len);
    }
};